package util

import (
	"os"
)

//支持过滤
func ChildDirs(dirname string, filter ...func(dir string) bool) ([]string, error) {
	f, err := os.Open(dirname)
	if err != nil {
		return nil, err
	}
	fis, err := f.Readdir(-1)
	if err != nil {
		return nil, err
	}
	dirs := make([]string, 0)
	for _, fi := range fis {

		if fi.IsDir() {
			if len(filter) == 0 || filter[0](fi.Name()) {
				dirs = append(dirs, fi.Name())
			}

		}
	}

	f.Close()
	return dirs, nil
}
